/*
 * powersys.h
 * This contain all the default methods for power system handling
 *  Created on: 12 Mar, 2009
 *      Author: suren
 */

#ifndef POWERSYS_H_
#define POWERSYS_H_

#include <vector>
#include <algorithm>
#include <string>
using namespace std;

// defnition of bus structure

struct bus {
  /* @busId  unique identifier of a bus */
  string name;
  int busNumber;

  /* @lossFlowZone and @lossFlowArea - find out what these variables are for ? */
  int lossFlowZone,lossFlowArea ;

  /* Type of the bus. Allowed values are
   * 0 - Unregulated (load, PQ)
   * 1 - Hold MVAR generation within voltage limits, (PQ)
   * 2 - Hold voltage within VAR limits (gen, PV)
   * 3 - Hold voltage and angle (swing, V-Theta) (must always have one slack bus)
   */
  int busType;

  double finalVoltage, finalDegree;

  /* Bus Load parameters P,Q, Reactive power limits and desiredVoltage*/
  double loadMW, loadMVAR, generatedMW, generatedMVAR;
  double BaseVoltage;
  double maxQ, minQ, shuntConductance, shuntSusceptance, maxP, minP, minV, maxV;

  /* given a line from data-file as a string, this constructor populates a bus information */
  bus(string inputLine);
};

//defnition of a branch structure

struct branch {
  /* @branchId unique identifier of a bus */
  int branchId ;

  /* @firstBus and @SecondBus - The two buses between the branches are present */
  int firstBus, secondBus;

  /* Find out the meaning of these variables */
  int lossFlowZone, lossFlowArea;

  /* @circuitType is to signify that the circuit is single phase or three phase and so on
   * 1 for single phase lines
   */
  int circuitType;

  /* @branchType is to find out the type of line the branch is. Allowed values are
   * 0 - Transmission line
   * 1 - Fixed tap
   * 2 - Variable tap for voltage control (TCUL, LTC)
   * 3 - Variable tap (turns ratio) for MVAR control
   * 4 - Variable phase angle for MW control (phase shifter)
   */
  int branchType;

  /* the following three variables are line Resistance, reactance and capacitence respectively. */
  double lineResistance, lineReactance, lineCharging;

  /* have to figure out what these variables are for */
  int lineMVARating,lineMVARatingEmergency, lineMVARatingshort;
  int controlBus, controlSide;

  /* transformer parameters - nature changes depending upon the @branchType */
  double transformerRatio, transformerAngle;
  double minTransformerparam, maxTransformerparam;
  double stepSize;

  /* Bus Voltage, MW or MVAR limits */
  double minBusLimit, maxBusLimit;

  int status;

  /* given a line from data-file as a string, this constructor populates a bus information */
  branch(string inputLine, int i);
};

//Definition of a generator Struct

struct generator{
  /* @generatorId is a unique identifier of Generator */
  int generatorId;

  /* @busId is the bus number of the generator bus */
  int busId;

  /* @Pg and @Qg are the two variables that are current generation values */
  double Pg, Qg;

  /* @realPowerOutput and reactivePowerOutput denotes the max capacity of the generator */
  double realPowerOutput, reactivePowerOutput;

  /* @MaxQ, MinQ, MaxP, MinP are the limits for real and reactive power limits */
  double maxQ, minQ, maxP, minP;

  /* Dunno what voltagesetpoint means, find the out */
  double voltageSetPoint, MVABase;

  /* status denotes if the generator is on or off */
  int status;

  generator(string inputLine);

};

// Major functions
vector<double> constructRandomVector(vector<struct bus> &Buses, vector<struct branch> &Branches, int i);


#endif /* POWERSYS_H_ */
